<?php namespace Home\Controller;

use Hdphp\Controller\Controller;
/**
 * 内容页管理控制器
 */
class ContentController extends Controller
{
	/*
	 * 首页
	 */
	 /**
	  * 此处商品id是给死的，后期需要把gid以及goods_gid改成灵活的
	  */
	public function index()
	{
		$gid = Q("get.gid",0,"intval");
		//获取商品表数据
		$goodsData = Db::table('goods')
				     ->where('gid','=',$gid)->first();
		//p($goodsData);
		//分配到页面
		View::with('goodsData',$goodsData);	
		/*
		 * 获得类型属性表数据（去颜色和尺码用class=2限制）
		 */
		$goodsData['selected'] = Db::table('typeattr')
		        ->where('type_tid','=',$goodsData['type_tid'])
				->where('class','=',2)
		        ->get();
		//p($goodsData);
		//循环把商品属性表数据压给类型数据
		foreach ($goodsData['selected'] as $k => $v) {
			$goodsData['selected'][$k]['spec'] = Db::table('goods_attr')
							 ->where('typeattr_taid','=',$v['taid'])
			                 ->where('goods_gid','=',$gid)
			                 ->get();
		}
		p($goodsData);
		//分配变量
		View::with('goodsData',$goodsData);
		//获取商品详情表数据
		$detailData = Db::table('detail')
					 ->where('goods_gid','=',$gid)
				     ->first();
		//p($detailData);	
		//将字符串转成数组
			$detailData['small'] = explode('|', $detailData['small']);
			$detailData['medium'] = explode('|', $detailData['medium']);
			$detailData['big'] = explode('|', $detailData['big']);
		//p($detailData);
		View::with('detailData',$detailData);
		//载入页面
		View::make('content');
	}

	


}
